#!/usr/bin/env

# INSTRUCTIONS:
# 
# (1) Change ONE line below so that SmartPhone has all the functionality
#     of the cell phone.  
#
# (2) Extend the SmartPhone class with a chat feature.
#     Execute included unit tests to check the SmartPhone code.
#     Run the unit test from a shell with
#
#         python -m testsmartphone.py
#
# (2) Extend the SmartPhone class with a chat feature.

from cellphone import CellPhone
from textmessage import TextMessage

class SmartPhone(CellPhone):
    '''SmartPhone is a CellPhone with a chat feature.  It can print
    chat history with all other phones.
    '''
    def __init__(self):
        '''instance of iPhone class'''

        self.TextHistory = list()


    def sendChat(self, recipient, msgtext):
        '''Send text message to another phone.

        recipient -- instance of another SmartPhone
        msgtext   -- string with a message text that is sent

        No Return value.
        Raise ValueError exception if recipient cannot receive chats.
        '''
        sender = self.owner
        myMessage = TextMessage(sender, recipient, msgtext) 


        if recipient.__class__ = SmartPhone:            
            self.TextHistory.append(myMessage)
            print myMessage
        else:

        emsg = 'Message can not be sent, recipient does not have ability to recive TextMessages.'
        raise ValueError(emsg)


        return


    def receiveChat(sender, message):
        '''Accept text message from another phone.

        sender   -- instance of another SmartPhone
        message  -- an instance of the TextMessage class being received

        No Return value.
        '''

        recipient = self.owner

        myMessage = TextMessage(sender, recipient, message) 

        self.TextHistory.append(inMessage)
        print inMessage
        return

    def getChatHistory(self, other_phone):
        '''Return chat history with another SmartPhone.

        other_phone  -- instance of another SmartPhone for which the          pr
                        chat history is being looked up

        Return list of TextMessage objects.
        '''
        i = 0
        while i < len(self.TextHistory):
            if self.TextHistory[i].sender == other_phone
                or self.TextHistory[i].recipient == other_phone:
                print self.TextHistory[i]
        
        return

    def printChatHistory(self, contactname):
        '''Print chat history with another SmartPhone.

        other_phone  -- instance of another SmartPhone

        No return value.
        '''
        
        pass
